﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using BackOffice.Context.UltiPro;
using BackOffice.Context.UltiPro.BackOfficeUIMapClasses;
using BackOffice.Context.UltiPro.Macros;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using System.Diagnostics;
using BackOffice.Context.UltiPro.PageObjects;
using System.Threading;

namespace BackOffice.Automation.Payroll
{
    //TODO: BackOffice PageObjects
    //TODO: Build BackOffice UI Map
    //TODO BackOffice Macros

    /// <summary>
    /// Summary description for AddHolidayCodes
    /// </summary>
    [CodedUITest]
    public class AddHolidayCodes
    {
        public static ApplicationUnderTest UltiPro;

        [ClassInitialize()]
        public static void ClassInitialize(TestContext context)
        {
            
        }

        [ClassCleanup()]
        public static void ClassCleanup()
        {            
            UIMacros.QuitUltiPro();
        }

        private BackOfficeUIMap UIMap
        {
            get
            {
                return new BackOfficeUIMap();
            }
        }        

        //Use TestInitialize to run code before running each test 
        [TestInitialize()]
        public void MyTestInitialize()
        {
            UltiPro = UIMacros.Launch(true);             
            UIMacros.Login("CALEN", "ULTI", "pros", "Web Payroll Company");
            Thread.Sleep(3000);
            UIMacros.OpenCodeSetup("Holidays");
        }

        //Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup()
        {            
            UIMacros.CloseCurrentWindow();
        }
        
        [TestMethod]        
        public void AddHolidayCode()
        {
            AddHolidayCode("Canada", "01012022", "New Holiday");
            DeleteHolidayCode("01/01/2022-CAN");

            CodeSetupMacros.ClickAddButton();

            UIMacros.SetComboBox(CodeSetup.Country, "Canada");
            Keyboard.SendKeys("01012030");
            UIMacros.SetEditBox(CodeSetup.Description, "New Holiday", true);

            CodeSetupMacros.ClickUndoButton();
            UIMacros.ConfirmWindowOK();
        }

        #region Helper Methods

        /// <summary>
        /// AddHolidayCode - Use 'AddHolidayCodeParams' to pass parameters into this method.
        /// </summary>
        public void AddHolidayCode(string holidayCountry, string holidateDate, string holidayDescription)
        {
            CodeSetupMacros.ClickAddButton();

            UIMacros.SetComboBox(CodeSetup.Country, holidayCountry);                                                
            Keyboard.SendKeys(holidateDate);
            UIMacros.SetEditBox(CodeSetup.Description, holidayDescription, true);
            
            CodeSetupMacros.ClickSaveButton();
        }

        public static void DeleteHolidayCode(string code)
        {
            CodeSetupMacros.SelectCode(code);
            CodeSetupMacros.ClickDeleteButton();
            UIMacros.ConfirmWindowOK();
        }

        #endregion

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        private TestContext testContextInstance;
    }
}
